package com.cn.ant.modules.wechat.service;

import com.cn.ant.common.persistence.Page;
import com.cn.ant.common.service.BaseService;
import com.cn.ant.modules.sys.entity.User;
import com.cn.ant.modules.sys.utils.UserUtils;
import com.cn.ant.modules.wechat.dao.WeiXinNewListTypeMapper;
import com.cn.ant.modules.wechat.entity.WeiXinNewListType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;
/**
 * 消息列表类型Service
 * @author AntDream
 * @version 2015-07-30
 */
@Component
@Transactional(readOnly = true)
public class WeiXinNewListTypeService extends BaseService {

	@Autowired
	private WeiXinNewListTypeMapper weiXinNewListTypeMapper;
	
	public WeiXinNewListType get(String id) {
		return weiXinNewListTypeMapper.get(id);
	}

	public WeiXinNewListType queryByCode(String code){
		return weiXinNewListTypeMapper.queryByCode(code);
	}
	
	public Page<WeiXinNewListType> find(Page<WeiXinNewListType> page, Map<String,Object> param) {
        param.put("startIdx", page.getFirstResult());
        param.put("pageSize", page.getPageSize());
        page.setList(weiXinNewListTypeMapper.query(param));
        page.setCount(weiXinNewListTypeMapper.queryCount(param));
        return page;
	}

    /**
     * 查询当前登录用户的消息列表
     * @return
     */
    public List<WeiXinNewListType> queryByLoginUser() {
        User user = UserUtils.getUser();
        return weiXinNewListTypeMapper.queryByLoginUser(user.getId());
    }

    @Transactional(readOnly = false)
	public void save(WeiXinNewListType weiXinNewListType) {
		weiXinNewListTypeMapper.insert(weiXinNewListType);
	}
	
	@Transactional(readOnly = false)
	public void update(WeiXinNewListType weiXinNewListType) {
		weiXinNewListTypeMapper.update(weiXinNewListType);
	}
	
	@Transactional(readOnly = false)
	public void delete(String id) {
		weiXinNewListTypeMapper.delete(id);
	}
	
}
